<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>yukari world</title>
<#include "/lib/base_source.ftl">
<style type="text/css">
</style>
</head>
<body>
<#include "/lib/mask.ftl">
<div class='whole-container'>
<#include "/lib/header.ftl">
    <div>
        <ul class="breadcrumb">
        	<li>兑换管理</li><span class="divider">/</span>
            <li>积分列表</li>
        </ul>
    </div>
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="container span12">
            <#include "/lib/alert.ftl">

                <div class='main-content'>

                    <div class="table-content">
                        <table class="table table-striped table-bordered table-condensed" id="itemTable" style="font-size:12px;word-break:break-all;word-wrap:break-word;">
                            <tr>
                                <th>物品名</th>
                                <th>兑换价格(积分)</th>
                                <th>兑换时间</th>
                                <th>兑换人</th>
                                <th>地址(姓名, 电话, 地址)</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                            <#list list as item>
                                <tr>
                                    <td>${item.exchangeGfit.name}</td>
                                    <td>${item.price}</td>
                                    <td>${item.createTime?string("yyyy-MM-dd HH:mm:ss")}</td>
                                    <td>${item.auth.name}</td>
                                    <td><#if item.address??>
                                        ${item.address.name},
                                        <span <#if !addressList??>style="background-color: #333;" onmouseover="this.style.color='#fff'"; onmouseout="this.style.color='#333'" </#if> >
                                             ${item.address.phone}
                                        </span>
                                        ,
                                        <span <#if !addressList??>style="background-color: #333;" onmouseover="this.style.color='#fff'"; onmouseout="this.style.color='#333'" </#if> >
                                              ${item.address.address}
                                        </span>

                                    </#if></td>

                                    <td>
                                        <#if item.status == 0>
                                            兑换成功
                                        <#elseif item.status == 1>
                                            快递发出<br/>
                                            ${item.expressName}<br/>
                                            <span <#if !addressList??>style="background-color: #333;" onmouseover="this.style.color='#fff'"; onmouseout="this.style.color='#333'" </#if> >
                                                ${item.expressNo}
                                        </span>

                                        <#elseif item.status == 2>
                                            已完成
                                        </#if>
                                    </td>
                                    <td>
                                        <#if addressList??>
                                            <#if item.exchangeGfit.type == 1>
                                                <#if  item.status == 0>
                                                    <a class="btn btn-sm btn-info" href="javascript:" onclick="showForm('${item.id}')">设置地址</a>
                                                <#elseif item.status == 1>
                                                    <a href="javascrupt:" onclick="updateSuccess('${item.id}')" class="btn btn-sm btn-success">已完成</a>
                                                </#if>
                                            <#else>
                                                <a href="javascrupt:" onclick="updateSuccess('${item.id}')" class="btn btn-sm btn-success">已完成</a>
                                            </#if>
                                        <#else>
                                            <#if item.exchangeGfit.type == 1>
                                                <#if item.status != 2 && item.address??>
                                                  <a class="btn btn-sm btn-info" href="javascript:" onclick="showExpress('${item.id}')">快递信息</a>
                                                </#if>
                                                <#if item.status == 1>
                                                    <a href="javascrupt:" onclick="updateSuccess('${item.id}')" class="btn btn-sm btn-success">已完成</a>
                                                </#if>
                                            <#elseif item.status != 2>
                                                <a href="javascrupt:" onclick="updateSuccess('${item.id}')" class="btn btn-sm btn-success">已完成</a>
                                            </#if>
                                        </#if>
                                    </td>
                                </tr>
                            </#list>
                        </table>
                    <#-- table -->

                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
<div class="maskDiv" id="updateAddressMaskDiv">
    <div onclick="hideAddressMaskDiv()" class="glyphicon glyphicon-remove" style="float: right"></div>
    <div class="form-horizontal" style="padding-top: 5%; font-size: 16px;">
        <form id="updateAddressForm">
            <input type="hidden" name="id" value="" id="id">
            <div class="control-group">
                <div class="control-label"></div>
                <div class="controls" style="width: 75%">
                    <a href="${rc.contextPath}/admin/address/add" class="btn btn-sm btn-info">新增地址</a>
                </div>
            </div>
            <#if addressList??>
                <#list addressList as item>
                    <div class="control-group">
                        <div class="control-label"><input type="radio" name="addressId" value="${item.id}" <#if item_index == 0>checked</#if> >${item_index+1}.</div>
                        <div class="controls" style="width: 75%">
                            ${item.name}, ${item.phone}, ${item.address}
                        </div>
                    </div>
                </#list>
                <#if (addressList?size > 0)>
                <div class="control-group">
                    <div class="control-label"></div>
                    <div class="controls" style="width: 75%;">
                        <a href="javascrupt:" onclick="updateAddressMaskDiv()" class="btn btn-sm btn-success">确认</a>

                    </div>
                </div>
                </#if>
            </#if>
        </form>
    </div>
</div>
<div class="maskDiv" id="updateExpressMaskDiv">
    <div onclick="hideUpdateExpressMaskDiv()" class="glyphicon glyphicon-remove" style="float: right"></div>
    <div class="form-horizontal" style="padding-top: 5%; font-size: 16px;">
        <form id="updateExpressForm">
            <input type="hidden" name="id" value="" id="ueId">
            <div class="control-group">
               <div class="control-label">快递公司</div>
               <div class="controls" style="width: 75%">
                    <input type="text" name="expressName" value="">
               </div>
            </div>
            <div class="control-group">
                <div class="control-label">快递单号</div>
                <div class="controls" style="width: 75%">
                    <input type="text" name="expressNo" value="">
                </div>
            </div>
            <div class="control-group">
                <div class="control-label"></div>
                <div class="controls" style="width: 75%">
                    <a href="javascrupt:" onclick="updateExpressMaskDiv()" class="btn btn-sm btn-success">确认</a>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    function showForm(hid){
        $("#id").val(hid);
        showMask();
        $("#updateAddressMaskDiv").show();
    }

    function hideAddressMaskDiv() {
        $("#id").val("");
        hideMask();
        $("#updateAddressMaskDiv").hide();
    }

    function updateAddressMaskDiv(){
        $.ajax({
            url : "${rc.contextPath}/admin/exchange/history/updateAddress",
            dataType : "json",
            data :  $("#updateAddressForm").serialize(),
            type:'post',
            success:function(json){
                if (json.code == 0){
                    location.reload();
                } else {
                    alert("设置失败: "+json.message);
                }
            }
        });
    }

    function showExpress(id) {
        $("#ueId").val(id);
        showMask();
        $("#updateExpressMaskDiv").show();
    }

    function hideUpdateExpressMaskDiv() {
        $("#ueId").val("");
        hideMask();
        $("#updateExpressMaskDiv").hide();
    }

    function updateExpressMaskDiv(){
        $.ajax({
            url : "${rc.contextPath}/admin/exchange/history/updateExpress",
            dataType : "json",
            data :  $("#updateExpressForm").serialize(),
            type:'post',
            success:function(json){
                if (json.code == 0){
                    location.reload();
                } else {
                    alert("填写失败: "+json.message);
                }
            }
        });
    }

    function updateSuccess(id){
        var txt = "请确认已完成要求或已收到货后再点<已完成>";
        if (confirm(txt)) {
            $.ajax({
                url: "${rc.contextPath}/admin/exchange/history/success",
                dataType: "json",
                data: {"id": id},
                type: 'post',
                success: function (json) {
                    if (json.code == 0) {
                        location.reload();
                    } else {
                        alert("修改失败: " + json.message);
                    }
                }
            });
        }
    }


</script>

</body>
</html>